var fs = require('fs');

var path = require('path')
var dir = '../db';

var schemaObj = {};

fs.readdir(dir, function (err, files) {

    // console.dir(file)
    // console.log(fs.readFileSync(file))
    // console.log(path.extname(file))
    files.forEach(ele => {

        // console.log(ele)
        // console.log(fs.readFileSync(path.join(dir,ele)))

        var tname = ele.substr(0,ele.indexOf("."));
        // console.log(tname)
        toSchema(tname)

    })

    console.log(JSON.stringify(schemaObj,null,2))
});

//  生成 schema

//  model 

//  insert data to db



function toSchema(tname){

    var str = fs.readFileSync('../db/'+tname+ ".json")
    var arr = JSON.parse(str);
    var item = arr[0]

    var schema = require('./dbSchema');

    var schemaJson = schema.getSchema(tname, item)
    schemaObj[tname] = schemaJson

}